package com.xzz.finger;

/**
 * @author: hhz
 * @create: 2022-02-21 09:56
 * 剑指 Offer 15. 二进制中1的个数
 **/
public class HammingWeight {
    public static void main(String[] args) {
        System.out.println(hammingWeight(-3 ));
    }
    public static int hammingWeight(int n) {
        int res = 0;
        while (n!=0){
            res++;
            n = n&(n-1);
        }
        return res;
    }
}
